<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <link href="../res/css/weui.css" rel="stylesheet" type="text/css" />
    <link href="../res/css/weuix.css" rel="stylesheet" type="text/css" />
    <link href="../res/css/mp_common.css" rel="stylesheet" type="text/css" />
	<link rel="stylesheet" href="../res/css/common.css" />
    <script src="../res/js/zepto.min.js" type="text/javascript"></script>
    <script src="../res/js/zepto.weui.js" type="text/javascript"></script>
    <script src="../res/js/php.js" type="text/javascript"></script>
    <script src="../res/js/picker.city.js" type="text/javascript"></script>
    <script src="../res/js/mp_common.js?v=1" type="text/javascript"></script>
    <script src="../res/js/common.js"></script>
    <style>        
        .weui-input{ font-size:14px;}
        label{ font-size:14px;}     
        input{
            text-align:left;
        }  
        .lable_div
        {
            height:20px;
            border:1px solid #b7b2b2;
            border-radius:5px;
            text-align:center;
            line-height:20px;
            font-size:10px;
            margin:5px;
        }
        table td
        {
            border:none;
        }     
		.weui-header .weui-header-left {
		    left: 6px;
		}
		#btnBuyOrder{
		    border-radius: 10px;
		    background: #1189ff;
		    color: #ffffff;
		}
    </style>
</head>
<body ontouchstart >
<div class="weui-cells weui-cells_form" style="margin:0px;">
	<div class="weui-header weui-btn_primary">
	    <div class="weui-header-left"><a id="btnBack" class="icon icon-109"></a></div>
	    <div class="weui-header-title">修改收货地址</div>
	    <div class="weui-header-right"></div>
	</div>
    <div class="weui-cell" style="margin-top:20px;">
        <div class="weui-cell__hd">
            <label class="weui-label" style="width:70px;">收货人</label>
        </div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="txt_name" placeholder="请输入收货人姓名" type="text">
        </div>
    </div>
    <div class="weui-cell" >
        <div class="weui-cell__hd">
            <label class="weui-label" style="width:70px;">手机号码</label>
        </div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="txt_tel" placeholder="请输入收货人手机号码" type="tel" maxlength="11">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd" style="width:70px;"><label class="weui-label">所在地区</label>
        </div>
        <div class="weui-cells weui-cells_form" id="region" style="margin-top:0px; width: 100%;">


            <div class="weui-cell" style="padding:0px;">
                <div class="weui-cell__bd">
                 
                    <input class="weui-input" id="txt_city" type="text" value="广东省 广州市 荔湾区">
                </div>
            </div>
        </div>
        <!--<input class="weui-input" id="txt_szdq" placeholder="请输入省（市）、市（区）、县（区）" value="" type="text">-->
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd" style="width:70px;"><label class="weui-label">详细地址</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="txt_xxdz" placeholder="如：道路、门牌号、小区、楼栋号、单元室等" value="" type="text">
        </div>
    </div> 
    <div class="weui-cell weui-cell_switch">
        <div class="weui-cell__bd"><label class="weui-label">设为默认地址</label></div>
        <div class="weui-cell__ft">
            <label for="switchCP" class="weui-switch-cp">
                <input id="switchCP" class="weui-switch-cp__input" type="checkbox">
                <div class="weui-switch-cp__box"></div>
            </label>
        </div>
    </div> 
    <div class="page-bd-15" style="margin-top:20px;">
        <a href="javascript:;" id="btnBuyOrder" class="weui-btn weui-btn_primary" onclick="address_num()">保&nbsp;&nbsp;存</a>
    </div>
    <br />
    <br />
    <!-- <div class="weui-flex" style="padding:5px 10px 0 10px; background-color:#05C1A9;"></div> -->
</div>
</body>
</html>
<script type="text/javascript">
    var lable_name = "";
    var str_name = "";
    var str_tel = "";
    var str_city = "";
    var str_xxdz = "";
    var str_default = "";
    var user_id = getQst("user_id").trim();
    var address_id = getQst("address_id").trim();  //地址id
    $(function () {
        //返回上页
        $('#btnBack').on("click", function () {
            history.go(-1);
        });
        
		$('#region').on('click',function(){
			$('#txt_name').blur();
			$('#txt_tel').blur();
			$('#txt_xxdz').blur();
		});
		getInfo()
    });
	
	function getInfo() {
		let params={"id": address_id}
		newAjaxPost("/h5/receivingAddress/getReceivingAddressInfo", params, getInfoOk);
	}
	function getInfoOk(jsonInfo){
		let rstData = jsonInfo.data
		if(jsonInfo.code == 1){
			$("#txt_name").val(rstData.userName);  //收货人
			$("#txt_tel").val(rstData.userPhone);   //电话
			$("#txt_city").val(rstData.address);  //城市地址
			$("#txt_xxdz").val(rstData.addressDetl);  //详细地址
			if(rstData.addressDeft == 1){
				//是默认地址
				$("#switchCP").attr('checked','checked');
			}else{
				//不是默认
			}
		}else{
			showJSZ(rstData.msg);
		}
	}

    ///选择收货地址
    $("#txt_city").cityPicker({
        title: "请选择收货地址",
        onChange: function (picker, values, displayValues) {

        }
    });

    //查询地址数量
    function address_num() {
        // debugger;
        str_name = $("#txt_name").val();  //收货人
        str_tel = $("#txt_tel").val();   //电话
        str_city = $("#txt_city").val();  //城市地址
        str_xxdz = $("#txt_xxdz").val();  //详细地址
		if($("#switchCP").is(':checked')==true){
			str_default = 1
		}else{
			str_default = 0
		}

        var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
        if (isSpace(str_name)) {
            showJSZ("请填写收货人姓名");
            return;
        }
        if (isSpace(str_tel)) {
            showJSZ("请填写收货人号码");
            return;
        }
        if (!myreg.test(str_tel)) {
            showJSZ("请填写正确的手机号码");
            return;
        }
        if (isSpace(str_city)) {
            showJSZ("请填写收货地址");
            return;
        }
        if (isSpace(str_xxdz)) {
            showJSZ("请填写收货详细地址");
            return;
        }
		//判断已创建地址数
		let params={
			"address": str_city,
			"addressCode": "",
			"addressDeft": str_default,
			"addressDetl": str_xxdz,
			"id": address_id,
			"lableName": "",
			"userId": user_id,
			"userName": str_name,
			"userPhone": str_tel
		}
		newAjaxPost("/h5/receivingAddress/updateReceivingAddress", params, get_addressOk);
    }
    function get_addressOk(jsonInfo){
		if (jsonInfo.code == "1") {
		    if (jsonInfo.msg== "修改成功") {
		        showJSZ("保存成功");
		        history.back(-1)
		    }
		    else {
		        showJSZ("保存失败");
		    }
		}else{
		    showJSZ(jsonInfo.msg);
		}
    }


    //返回列表
    function ToPage() {
        /* actToPage('user_list.htm?user_id=' + user_id); */
		history.back(-1)
    }
</script>
